package cn.IT.Nf.Test.Servlet;

import cn.IT.Nf.Test.Dao.Impl.StaffsDaoImpl;
import cn.IT.Nf.Test.Dao.StaffsDao;
import cn.IT.Nf.Test.Entity.Staffs;
import com.google.gson.Gson;
import jakarta.servlet.*;
import jakarta.servlet.annotation.*;
import jakarta.servlet.http.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/staffsServlet")
public class StaffsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StaffsDao goodsDao = new StaffsDaoImpl();
        List<Staffs> list = goodsDao.select();
        Gson gson = new Gson();
        String json = gson.toJson(list);
        PrintWriter out = response.getWriter();
        out.write(json);
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
